button: Add explicit key bindings for activation
authorMatthias Clasen <mclasen@redhat.com>
Sat, 18 Jul 2020 16:51:18 +0000 (12:51 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 18 Jul 2020 16:53:10 +0000 (12:53 -0400)
We should not rely on GtkWindow to have global
"activate-default" key bindings that happen to
fall back to activating the focus widget. This is
unreliable, since the bubbling up from the button
to the toplevel may run across other widgets that
may want to use Enter for their own purpose, and
then the button loses out. By adding our own
key bindings, the button gets to handle it before
its ancestors.

This fixes check buttons in the inspector property
list not reacting to Enter despite having focus.

gtk/gtkbutton.c

index 8a0c084b5221791e215a2754c78f31f92f9dfc26..2cb79cc4839be7df393dd6867383b3462e178234 100644 (file)
@@ -294,6 +294,17 @@ gtk_button_class_init (GtkButtonClass *klass)
   gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_BUTTON_ACCESSIBLE);
   gtk_widget_class_set_css_name (widget_class, I_("button"));
+
+  gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0,
+                                       "activate", NULL);
+  gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0,
+                                       "activate", NULL);
+  gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0,
+                                       "activate", NULL);
+  gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0,
+                                       "activate", NULL);
+  gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0,
+                                       "activate", NULL);
 }
 
 static void